package com.blaze.framework.core.cloud.http;

import okhttp3.OkHttpClient;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;

import java.sql.Time;
import java.util.concurrent.TimeUnit;

/**
 * 远程调用配置
 * {@link okhttp3.logging.HttpLoggingInterceptor}
 * @author created by Zhou Zongbo on 2025/5/23.
 */
@AutoConfiguration
@ConditionalOnClass(OkHttpClient.class)
@ConditionalOnProperty(value = "blaze.http.enabled", matchIfMissing = true)
public class RemoteTemplateConfiguration {

    @Bean
    @ConditionalOnMissingBean
    public OkHttpClient okHttpClient() {
        return new OkHttpClient.Builder()
                .connectTimeout(10, TimeUnit.SECONDS)
                .readTimeout(60, TimeUnit.MINUTES)
                .writeTimeout(60, TimeUnit.MINUTES)
                .addInterceptor(new OkHttpLogInterceptor(new OkHttpLog()))
                .build();
    }
}
